package com.csweimei.rentmanagementtreasure.enterprise.act;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppViewModelFactory;
import com.csweimei.rentmanagementtreasure.databinding.ActivityBuyCodeBinding;
import com.csweimei.rentmanagementtreasure.enterprise.viewModel.BuyCodeVM;
import com.gtdev5.geetolsdk.mylibrary.beans.Gds;
import com.gtdev5.geetolsdk.mylibrary.beans.UpdateBean;
import com.gtdev5.geetolsdk.mylibrary.util.DataSaveUtils;
import com.gtdev5.geetolsdk.mylibrary.util.ToastUtils;

import me.goldze.mvvmhabit.base.BaseActivity;

public class BuyCodeActivity extends BaseActivity<ActivityBuyCodeBinding, BuyCodeVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_buy_code;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);


        binding.edt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().equals("0")){
                    ToastUtils.showShortToast("最后购买一个席位码");
                    viewModel.num.set(1);
                    viewModel.numT.set("1");
                    viewModel.compute();
                }else {
                    viewModel.num.set(Integer.valueOf(s.toString()));
                    viewModel.numT.set(s.toString());
                    viewModel.compute();
                }

            }
        });
    }

    @Override
    public BuyCodeVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this,factory).get(BuyCodeVM.class);
    }
}